package com.xc.freeapp.account.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xc.freeapp.bean.AuthInfo;
import com.xc.freeapp.common.CheckUtils;
import com.xc.freeapp.entity.Picscroll;
import com.xc.freeapp.exception.BaseException;
import com.xc.freeapp.service.HospitalService;
import com.xc.freeapp.service.PicscrollService;
import com.xc.freeapp.util.AuthUtil;
import com.xc.freeapp.util.Constant;
import com.xc.freeapp.util.JsonUtil;
import com.xc.freeapp.util.TokenAnnotation;
import com.xc.freeapp.util.UploadUtil;
/**
 * app海报轮播模块controller
 * @author ZhouXinjie
 */
@Controller
@RequestMapping("/picscroll")
@Api(value="/picscroll",description = "海报轮播")
public class PicscrollController extends AbstractController{
	
	@Autowired
	private PicscrollService picscrollService;
	@Autowired
	private HospitalService hospitalService;
	@Autowired
	AccountController accountController;
	/**
	 * 根据医院id查询轮播海报列表
	 */
	@TokenAnnotation(required=false)
	@RequestMapping(value = "", method = RequestMethod.GET)
	@ResponseBody 
	@ApiOperation(value = "根据医院id查询轮播海报列表")
	public List<Picscroll> getList() throws BaseException{
		AuthInfo authInfo = AuthUtil.getAuthInfo(getRequest());
		
		accountController.openApp();//插入日活用户
		
		Integer status = hospitalService.selectappstatus(authInfo.getAppIntId());
		if(status==null||status==0){
			throw new BaseException(Constant.ERRORCODE_444);
		}
		Map<String, Object> paramsmap=new HashMap<String, Object>();
		paramsmap.put("businessId", authInfo.getAppId());
		List<Picscroll> picscrolllist = picscrollService.getList(paramsmap);
		for (Picscroll picscroll : picscrolllist) {
			picscroll.setPic(UploadUtil.urlConversion(picscroll.getPic()));
		}
		if(picscrolllist==null||picscrolllist.size()==0){
			paramsmap.put("businessId", "-1");
			picscrolllist = picscrollService.getList(paramsmap);
			for (Picscroll picscroll : picscrolllist) {
				picscroll.setPic(UploadUtil.urlConversion(picscroll.getPic()));
			}
		}
		return picscrolllist;
	}
	
}
